/* Maple Coin trader
Made By: Kippieeej/bassoe
	 
*/
importPackage(net.sf.odinms.net.channel);
importPackage(net.sf.odinms.client);
importPackage(net.sf.odinms.tools);

var status = 0;
var items = Array(1302081, 1302101, 1312037, 1322060, 1322062, 1402046, 1412033, 1422037, 1482023, 1492013, 1322063, 1322064, 1372035, 1372036, 1372037, 1372038, 1372039, 1372040, 1372041, 1372042, 1382045, 1382046, 1382047, 1382048, 1382049, 1382050, 1382051, 1382052);
var needed = Array(30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 5, 10, 20, 20, 20, 20, 40, 40, 40, 40, 30, 30, 30, 30, 30, 50, 50, 50, 50);
var selectedItem = 0;
var chicken = 0;
var blabla = 0;
var minutes = 1;
var clockminutes = (minutes * 60);
var timerminutes = (clockminutes * 1000);

importPackage(net.sf.odinms.client);

function start() {
	status = -1;
	action(1, 0, 0);
}

function action(mode, type, selection) {
	if (mode == -1) {
		cm.dispose();
	} else {
		if (status >= 2 && mode == 0) {
			cm.sendOk("Alright, see you next time.");
			cm.dispose();
			return;
		}
		if (mode == 1)
			status++;
		else
			status--;
		if (status == 0) {
			cm.sendSimple("Hello #b#h ##k, You have #c4001129# #i4001129#\r\n#L1##bI want to buy cool items#l\r\n#L2#I want to go to Free market <1> to <4>#k#l");
		} else if (status == 1) {
			if (selection == 1) {
				cm.sendNextPrev("What would you like to buy?")
				chicken = 1;
			} else {
				cm.sendSimple("#L1##bI wanna go FM<1> (1mil)#l\r\n#L2##bI wanna go FM<2> (1mil)#l\r\n#L3##bI wanna go FM<3> (1mil)#l\r\n#L4##bI wanna go FM<4> (1mil)#k#l");
				selection = blabla;
				chicken = 2;
			}
		} else if (status == 2) {
			if (chicken == 1) {
				var selStr = "Select your items.#b";
					for (var i = 0; i < items.length; i++) {
						selStr += "\r\n#L" + i + "##t" + items[i] + "# (#i" + items[i] + "#) = " + needed[i] + " maplecoins#l";
					}
				cm.sendSimple(selStr);
			} else if (selection > 0) {
				if (cm.getMeso() >= 1000000) {
					cm.warp(910000000 + selection);
					cm.gainMeso(-1000000);
					cm.getChar().getClient().getSession().write(net.sf.odinms.tools.MaplePacketCreator.getClock(clockminutes));
					cm.startTimer(910000000, timerminutes);
					cm.dispose();
				} else {
					cm.sendOk("You dont have enough Mesos");
					cm.dispose();
				}
			}
		} else if (status == 3) {
			if (chicken = 1) {
				if (cm.itemQuantity(4001129) < needed[selection]) {
					cm.sendOk("You do not have enough Maple coins.")
					cm.dispose();
				} else {
					cm.sendYesNo("So you Want #t" + items[selection] + "#? (#i" + items[selection] + "#)");
					selectedItem = selection;
				}	
			} else {
				cm.dispose();
			}	
		} else if (status == 4) {
			cm.gainItem(4001129, -needed[selectedItem]);
			cm.gainItem(items[selectedItem], 1);
			cm.dispose();
		}
	}
}	